package com.jiyun;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Map;
import java.util.Set;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class SpringdataRedisDemo_Set {

    @Autowired
    RedisTemplate redisTemplate;

    /*
    set类型增删改查  key—HashSet
     */

    @Test
    public void add(){
     redisTemplate.boundSetOps("school").add("aaa","bbb","ccc","bbb");
    }

    @Test
    public void query(){
        Set school = redisTemplate.boundSetOps("school").members();
        for (Object o : school) {
            System.out.println(o);
        }
    }

    @Test
    public void delItem(){
        //单个精确移除
        //redisTemplate.boundSetOps("school").remove("bbb");
        //随机移除一个
        //redisTemplate.boundSetOps("school").pop();
        //是否是set中的元素
        System.out.println(redisTemplate.boundSetOps("school").isMember("bbb"));
    }
    @Test
    public void del(){
        redisTemplate.delete("user");
    }



}
